{include file="common/header"}
<div id="app" v-cloak>
    <div class="el-pane-warp">
        <el-form ref="ruleForm" :model="config" :rules="rules" label-width="200px">
            <el-form-item label="开发者ID(AppID)：" prop="appid">
                <el-input v-model="config.appid" show-password></el-input>
                <el-link href="https://mp.weixin.qq.com/advanced/advanced?action=dev&t=advanced/dev&token=1433954847&lang=zh_CN" target="_blank">点击取得您的appid</el-link>
            </el-form-item>
            <el-form-item label="开发者密码(AppSecret)：" prop="secret">
                <el-input type="password" v-model="config.secret" show-password></el-input>
                <el-link href="https://mp.weixin.qq.com/advanced/advanced?action=dev&t=advanced/dev&token=1433954847&lang=zh_CN" target="_blank">点击取得您的secret</el-link>
            </el-form-item>
            <el-form-item label="开启状态：" prop="open">
                <el-switch
                    v-model="config.open"
                    :active-value="1"
                    :inactive-value="0">
                </el-switch>
            </el-form-item>
        </el-form>
        <div class="el-bottom" style="width: 100%">
            <el-button 
                :loading="loading"
                type="primary" 
                size="medium" 
                icon="el-icon-refresh-right"
                @click="save()">
                保 存
            </el-button>
        </div>
    </div>
</div>
<script>
new Vue({
    el: '#app',
    data() {
        return {
            config: {:json_encode($config)},
            loading: false,
            updateUrl: "wechatlogin/config/index",
            rules: {
                appid: [
                    { required: true, message: '请填写开发者ID(AppID)', trigger: 'blur' },
                ],
                secret: [
                    { required: true, message: '请填写开发者密码(AppSecret)', trigger: 'blur' },
                ],
                open: [
                    { required: true, message: '请选择是否开启', trigger: 'blur' },
                ]
            },
        }
    },
    methods: {
        /**
         * 保存数据
         */
        save() {
            let self = this;
            self.$refs.ruleForm.validate((valid) => {
                if (valid) {
                    self.loading = true;
                    request.post(self.updateUrl, {value: self.config}, function(res){
                        self.loading = false;
                        self.$notify({showClose: true, message: res.message, type: res.status});
                    });
                } else {
                    return false;
                }
            });
        },
    },
})
</script>
{include file="common/footer"}